Imports ccapps.persistent.corporateDealer
Namespace Web.page

Public Class CorporateDealer
    Inherits [lib].BasePage
        Protected WithEvents Lblok As System.Web.UI.WebControls.Label
        Protected WithEvents ddl_corp As System.Web.UI.WebControls.DropDownList
        Protected WithEvents proc As System.Web.UI.HtmlControls.HtmlInputHidden
        Protected WithEvents txt_dealercode As System.Web.UI.WebControls.TextBox
        Protected WithEvents DG_CUST As System.Web.UI.WebControls.DataGrid



#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region


    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
            Me.PageTitle = "Corporate Dealers"

            Dim Vproc As String
            Vproc = Me.proc.Value
            Me.proc.Value = ""

            Select Case Vproc
                Case "save"
                    save()
                Case "show"
                    show()
                Case Else
                    getListCombo()
            End Select


            
    End Sub

        Public Sub getListCombo()
            'Dim SQL As String
            'SQL = " select cu.customer_id CUSTID ,cu.custcode||' '||cc.cclname  CORP from  customer_all cu,ccontact_all cc"
            'SQL = SQL & " where cc.customer_id=cu.customer_id"
            'SQL = SQL & " and cc.ccbill='X'"
            'SQL = SQL & " and cu.custcode like '45%'"
            Me.ddl_corp.DataSource = getListData()
            Me.ddl_corp.DataTextField = "CORP"
            Me.ddl_corp.DataValueField = "CUSTID"
            Me.ddl_corp.DataBind()

        End Sub

        Private Sub save()
            Dim temp As DataTable
            Dim sql As String
            Me.Lblok.Text = ""
            'Dim os_user As String = Request.ServerVariables("LOGON_USER")
            Dim os_user As String = Session("user")
            temp = getCorpDealer(Me.ddl_corp.SelectedItem.Value)
            'sql = "SELECT * FROM ittemp.corp_dealers where corp_dealer_id=" & Me.ddl_corp.SelectedItem.Value & ""
            If Trim(Me.txt_dealercode.Text) = "" Then
                'Response.Write("<SCRIPT language=""JavaScript"">" & vbCrLf & "{" & vbCrLf)
                'Response.Write("alert("" Please enter dealer code "")" & vbCrLf)
                'Response.Write("}" & vbCrLf & "</SCRIPT>" & vbCrLf)
                Message = "alert('Please enter dealer code');"
            ElseIf temp.Rows.Count > 0 Then
                Me.Lblok.Text = "Error:This corporate has  already been  inserted before. Record has not been saved!!"
            Else
                'Dim LSTR As Integer = Len(Trim(Me.txt_dealercode.Text))
                'Dim dcode As String = Right(Trim(Me.txt_dealercode.Text), LSTR - 1)
                Dim dcode As String = RTrim(Me.txt_dealercode.Text)
                'sql = "select * from dealer where custcode='" & dcode & "'"
                If getDealerCount(dcode).Rows.Count > 0 Then
                    'sql = "insert into ittemp.corp_dealers  values (" & Me.ddl_corp.SelectedItem.Value & ",'" & Trim(Me.txt_dealercode.Text) & "','" & os_user & "',sysdate)"
                    insertCorpDealer(Me.ddl_corp.SelectedItem.Value, Trim(Me.txt_dealercode.Text), os_user)
                    'ds.ORAExecute(sql)
                    Me.Lblok.Text = "Record has been saved!"
                    Me.txt_dealercode.Text = ""
                    If tmp = 1 Then
                        SHOW_DEALERS()
                    End If
                Else
                    Me.Lblok.Text = "Error:Not able to find the dealer code. Please enter valid dealer code!!"
                End If
            End If

            'ds = Nothing
        End Sub

        Private Sub show()
            SHOW_DEALERS()
            'If tmp = 0 Then
            '    tmp = 1
            '    SHOW_DEALERS()
            '    'Me.BTN_SHOW.Text = "Hide Corp.Dealers"

            'Else
            '    Me.BTN_SHOW.Text = "Show Corp.Dealers"
            '    tmp = 0
            '    Me.DG_CUST.Visible = False
            '    Me.Lblok.Text = ""
            'End If

        End Sub

        Sub SHOW_DEALERS()

            Dim temp As DataTable
            'Dim DS As New myDBConn
            'SQL = " SELECT cus.custcode||' '||cc.CCLNAME cname,corp.dealer_code  code"
            'SQL = SQL & " FROM ittemp.corp_dealers corp,customer_all cus,ccontact_all cc"
            'SQL = SQL & " where cc.customer_id=cus.customer_id"
            'SQL = SQL & " and cus.customer_id=corp.CORP_DEALER_ID"
            'SQL = SQL & " and cc.ccbill='X' and cus.customer_id<1"
            temp = getDataGrid()
            If temp.Rows.Count > 0 Then
                Me.DG_CUST.DataSource = temp
                Me.DG_CUST.DataBind()
                Me.DG_CUST.Visible = True
            Else
                Me.DG_CUST.Visible = False
                Me.Lblok.Text = "No data found!!"
            End If
            'DS = Nothing
        End Sub
End Class

End Namespace